package com.evan.review.architecture.mvi.viewstate;

/**
 * MVI架构中的ViewState
 * 表示UI的状态，是不可变的
 */
public class CounterViewState {
    
    private final int count;
    private final boolean isLoading;
    private final String error;
    
    private CounterViewState(int count, boolean isLoading, String error) {
        this.count = count;
        this.isLoading = isLoading;
        this.error = error;
    }
    
    // 初始状态
    public static CounterViewState initial() {
        return new CounterViewState(0, false, null);
    }
    
    // 加载状态
    public CounterViewState loading() {
        return new CounterViewState(this.count, true, null);
    }
    
    // 成功状态
    public CounterViewState success(int count) {
        return new CounterViewState(count, false, null);
    }
    
    // 错误状态
    public CounterViewState error(String error) {
        return new CounterViewState(this.count, false, error);
    }
    
    // Getters
    
    public int getCount() {
        return count;
    }
    
    public boolean isLoading() {
        return isLoading;
    }
    
    public String getError() {
        return error;
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        
        CounterViewState that = (CounterViewState) o;
        
        if (count != that.count) return false;
        if (isLoading != that.isLoading) return false;
        return error != null ? error.equals(that.error) : that.error == null;
    }
    
    @Override
    public int hashCode() {
        int result = count;
        result = 31 * result + (isLoading ? 1 : 0);
        result = 31 * result + (error != null ? error.hashCode() : 0);
        return result;
    }
    
    @Override
    public String toString() {
        return "CounterViewState{" +
                "count=" + count +
                ", isLoading=" + isLoading +
                ", error='" + error + '\'' +
                '}';
    }
} 